<template>
<div>
   <div class="g_top_box">
		<div class="g_right_box"></div> 
		<div class="g_left_box"><h4>部门信息</h4></div>
	</div>
	<div class="g_content_box">

		<Form :model="info" label-position="left" :label-width="100">


			<FormItem label="名称">
				<Input v-model="info.name" style="width:200px;"></Input>
			</FormItem>
			<FormItem label="权限设置">
				<div v-for="(val,index) in priv_list">
					<check_group :data="val" :ref="'check_'+index"></check_group>
				</div>
			</FormItem>
			<FormItem>
				<Button type="primary" @click="save">修改</Button>
			</FormItem>
		</Form>

		
	</div>
</div>
</template>

<script>
import Wcore from '@/libs/common';
import check_group from '@/themes/components/check_group';


export default {
    name: 'bumen_info',
    data (){
		
        return {
            info:{
				name:''
			},
			id:0,
			priv_list:[]
        };
    },
	components: {
       check_group
    },
	created(){
		this.id = this.$route.params.id;
		this.load_data();
		
		this.$emit('change','bumen');
	},
    computed: {
       
    },
	methods:{
		load_data(){
			var self = this;
			var postdata = {
				id:this.id
			};
			Whttp.load('User/Bumen/get_info',postdata,function(result){
				self.info = result;
				self.load_priv();
			});
		},
		save(){
			var self = this;
			
			
			var priv_arr = [];

			for(var i=0;i<this.priv_list.length;i++){
				var ref = 'check_'+i;
				var comm = this.$refs[ref][0];
				
				var ls_arr = comm.get_sel_value();
				for(var k=0;k<ls_arr.length;k++){
					priv_arr.push(ls_arr[k]);
				}
			}
			
			var postdata = {
				id:this.id,
				name:this.info.name,
				privs:priv_arr.join(',')
			};
			Whttp.load('User/Bumen/save',postdata,function(result){
				self.$Message.info('保存成功');
				self.$router.back();
			});
		},
		load_priv(){
			var self = this;
			var privs = self.info.privs.split(',');
			
			Whttp.load('System/Role/get_priv_list',{},function(result){
				self.priv_list = result;
				var list = self.priv_list;
				
				for(var i =0;i<list.length;i++){
					for(var j=0;j<list[i].children.length;j++){
						
						if(privs.in_array(list[i].children[j].code)){
							
							list[i].children[j].choose = 1;
						}
					}
					
					if(privs.in_array(list[i].code)){
						list[i].choose = 1;
					}
				}
			});
		},
	}
};
</script>
<style scoped>

</style>